package cn.laixueit.controller;

import cn.laixueit.pojo.Users;
import cn.laixueit.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/login")
    public @ResponseBody  Boolean login(Users users, HttpSession session){
        Boolean login = userService.login(users);
        if(login){
            session.setAttribute("status",users);
        }
        return login;
    }

    @GetMapping("/logout")
    public @ResponseBody Boolean logout( HttpSession session){
        session.removeAttribute("status");
        return true;
    }
}
